package itsm.isperp.framework.web.utils;

import java.lang.reflect.Field;
import java.util.Map;

import javax.servlet.ServletRequest;

/**
 * 
 * Http服务请求工具
 * 
 * @author lizx
 * @date 2014-3-27
 * @since 1.0
 * 
 */
public class HttpServletRequestUtils {

	public static Map<String, String[]> getRequestMap(ServletRequest request)
			throws ClassNotFoundException, NoSuchFieldException,
			SecurityException, IllegalArgumentException, IllegalAccessException {
		Field requestField;

		Field parametersParsedField;

		Field coyoteRequestField;

		Field parametersField;

		Field hashTabArrField;
		Class<?> clazz = Class
				.forName("org.apache.catalina.connector.RequestFacade");
		requestField = clazz.getDeclaredField("request");
		requestField.setAccessible(true);

		parametersParsedField = requestField.getType().getDeclaredField(
				"parametersParsed");
		parametersParsedField.setAccessible(true);

		coyoteRequestField = requestField.getType().getDeclaredField(
				"coyoteRequest");
		coyoteRequestField.setAccessible(true);

		parametersField = coyoteRequestField.getType().getDeclaredField(
				"parameters");
		parametersField.setAccessible(true);

		hashTabArrField = parametersField.getType().getDeclaredField(
				"paramHashValues");
		hashTabArrField.setAccessible(true);

		Object innerRequest = requestField.get(request);
		parametersParsedField.setBoolean(innerRequest, true);
		Object coyoteRequestObject = coyoteRequestField.get(innerRequest);
		Object parameterObject = parametersField.get(coyoteRequestObject);
		return (Map<String, String[]>) hashTabArrField.get(parameterObject);

	}

}
